<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}{{ system_config.site_name|default('会员系统') }}{% endblock %}-会员系统</title>
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --light-bg: #f8f9fa;
            --sidebar-width: 260px;
            --header-height: 70px;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f7fb;
            color: #495057;
            overflow-x: hidden;
        }

        /* 顶部导航栏样式 */
        .main-header {
            height: var(--header-height);
            background: linear-gradient(120deg, var(--primary-color), var(--secondary-color));
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            z-index: 1030;
        }

        .brand-logo {
            font-weight: 700;
            font-size: 1.5rem;
            color: white;
        }

        .user-menu {
            background: rgba(255, 255, 255, 0.15);
            border-radius: 50px;
            padding: 0.35rem 0.8rem;
            transition: all 0.3s;
        }

        .user-menu:hover {
            background: rgba(255, 255, 255, 0.25);
        }

        /* 主内容区域样式 */
        .main-container {
            margin-top: var(--header-height);
            display: flex;
            min-height: calc(100vh - var(--header-height));
            transition: all 0.3s;
        }

        /* 侧边栏样式 */
        .sidebar {
            width: var(--sidebar-width);
            background: white;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.05);
            transition: all 0.3s ease;
            z-index: 1020;
            height: calc(100vh - var(--header-height));
            overflow-y: auto;
            position: fixed;
            left: 0;
        }

        .sidebar.collapsed {
            transform: translateX(-100%);
        }

        .sidebar-menu {
            padding: 1.5rem 0;
        }

        .menu-item {
            display: flex;
            align-items: center;
            padding: 0.85rem 1.5rem;
            color: #495057;
            text-decoration: none;
            transition: all 0.2s;
            border-left: 3px solid transparent;
        }

        .menu-item:hover, .menu-item.active {
            background-color: var(--light-bg);
            color: var(--primary-color);
            border-left-color: var(--primary-color);
        }

        .menu-item i {
            width: 24px;
            margin-right: 12px;
        }

        /* 内容区域样式 */
        .content-area {
            flex: 1;
            padding: 2rem;
            transition: all 0.3s;
            margin-left: var(--sidebar-width);
        }

        .content-area.expanded {
            margin-left: 0;
        }

        .dashboard-card {
            background: white;
            border-radius: 12px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
            transition: transform 0.3s, box-shadow 0.3s;
            height: 100%;
        }

        .dashboard-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
        }

        .stat-number {
            font-size: 2.2rem;
            font-weight: 700;
            color: var(--primary-color);
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                transform: translateX(-100%);
            }

            .sidebar.mobile-active {
                transform: translateX(0);
            }

            .content-area {
                margin-left: 0;
                width: 100%;
            }

            .overlay {
                display: none;
                position: fixed;
                top: var(--header-height);
                left: 0;
                right: 0;
                bottom: 0;
                background: rgba(0, 0, 0, 0.5);
                z-index: 1015;
            }

            .overlay.active {
                display: block;
            }
        }

        /* 自定义滚动条 */
        ::-webkit-scrollbar {
            width: 6px;
        }

        ::-webkit-scrollbar-track {
            background: #f1f1f1;
        }

        ::-webkit-scrollbar-thumb {
            background: #c5c5c5;
            border-radius: 10px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: #a8a8a8;
        }
    </style>
</head>
<body>
<!-- 顶部导航栏 -->
<header class="main-header">
    <div class="container-fluid h-100">
        <div class="d-flex align-items-center justify-content-between h-100">
            <div class="d-flex align-items-center">
                <button class="btn text-white me-2 d-lg-none" id="sidebarToggle">
                    <i class="fas fa-bars"></i>
                </button>
                <a href="{{ url_for('member.index') }}" class="brand-logo text-decoration-none">
                    <i class="fas fa-tasks me-2"></i>{{ system_config.site_name|default('会员系统') }}
                </a>
                <button class="btn text-white ms-3 d-none d-lg-block" id="toggleSidebarGlobal">
                    <i class="fas fa-eye-slash"></i>
                </button>
            </div>

            <div class="dropdown">
                <a class="text-decoration-none d-flex align-items-center user-menu text-white dropdown-toggle" href="#" role="button" id="userDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                    <i class="fas fa-user-circle me-2"></i> {{ session.member_name }}
                </a>
                <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
                    <li><a class="dropdown-item" href="{{ url_for('member.userinfo.view_profile') }}">
                        <i class="fas fa-user me-2"></i>个人信息
                    </a></li>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item" href="{{ url_for('member.auth.logout') }}">
                        <i class="fas fa-sign-out-alt me-2"></i>退出登录
                    </a></li>
                </ul>
            </div>
        </div>
    </div>
</header>

<!-- 主内容区域 -->
<div class="main-container">
    <!-- 侧边栏 -->
    <aside class="sidebar">
        <div class="sidebar-menu">
            <h6 class="px-4 text-uppercase small text-muted mb-3">主导航</h6>

            <a href="{{ url_for('member.index') }}" class="menu-item {% if request.endpoint == 'member.index' %}active{% endif %}">
                <i class="fas fa-home"></i>首页
            </a>

            <a href="{{ url_for('member.dashboard') }}" class="menu-item {% if request.endpoint == 'member.dashboard' %}active{% endif %}">
                <i class="fas fa-tachometer-alt"></i>仪表盘
            </a>

            <a href="{{ url_for('member.member_stats') }}" class="menu-item {% if request.endpoint == 'member.member_stats' %}active{% endif %}">
                <i class="fas fa-chart-line"></i>工作统计
            </a>

            <!-- 项目管理 -->
            <h6 class="px-4 text-uppercase small text-muted mt-4 mb-2">项目管理</h6>
            <a href="{{ url_for('member.jira.list_projects') }}" class="menu-item {% if request.endpoint == 'member.jira.list_projects' %}active{% endif %}">
                <i class="fas fa-folder-open"></i>我的项目
            </a>
            <a href="{{ url_for('member.jira.create_project') }}" class="menu-item {% if request.endpoint == 'member.jira.create_project' %}active{% endif %}">
                <i class="fas fa-plus-circle"></i>创建项目
            </a>

            <!-- 任务管理 -->
            <h6 class="px-4 text-uppercase small text-muted mt-4 mb-2">任务管理</h6>
            <a href="{{ url_for('member.task.list_tasks') }}" class="menu-item {% if request.endpoint == 'member.task.list_tasks' %}active{% endif %}">
                <i class="fas fa-tasks"></i>我的任务
            </a>

            <!-- 审批管理 -->
            <h6 class="px-4 text-uppercase small text-muted mt-4 mb-2">审批管理</h6>
            <a href="{{ url_for('member.approval.list_approvals') }}" class="menu-item {% if request.endpoint.startswith('member.approval.list_approvals') %}active{% endif %}">
                <i class="fas fa-clipboard-check"></i>我的审批
            </a>
            <a href="{{ url_for('member.approval.review_list') }}" class="menu-item {% if request.endpoint.startswith('member.approval.review') %}active{% endif %}">
                <i class="fas fa-check-double"></i>待我审批
                {% if pending_approval_count and pending_approval_count > 0 %}
                <span class="badge bg-danger rounded-pill ms-auto">{{ pending_approval_count }}</span>
                {% endif %}
            </a>

            <!-- 个人中心 -->
            <h6 class="px-4 text-uppercase small text-muted mt-4 mb-2">个人中心</h6>
            <a href="{{ url_for('member.userinfo.view_profile') }}" class="menu-item {% if request.endpoint == 'member.userinfo.view_profile' %}active{% endif %}">
                <i class="fas fa-user-cog"></i>个人信息
            </a>
            <a href="{{ url_for('member.userinfo.edit_profile') }}" class="menu-item {% if request.endpoint == 'member.userinfo.edit_profile' %}active{% endif %}">
                <i class="fas fa-user-edit"></i>修改资料
            </a>
        </div>
    </aside>

    <!-- 移动设备遮罩层 -->
    <div class="overlay" id="overlay"></div>

    <!-- 内容区域 -->
    <div class="content-area" id="contentArea">
        <!-- 消息提示 -->
        {% with messages = get_flashed_messages(with_categories=true) %}
        {% if messages %}
        {% for category, message in messages %}
        <div class="alert alert-{{ 'danger' if category == 'error' else category }} alert-dismissible fade show mb-4"
             role="alert" data-bs-autohide="true" data-bs-delay="5000">
            <div class="d-flex align-items-center">
                <i class="fas {% if category == 'error' %}fa-exclamation-circle{% elif category == 'success' %}fa-check-circle{% else %}fa-info-circle{% endif %} me-2"></i>
                <div>{{ message }}</div>
            </div>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
        {% endfor %}
        {% endif %}
        {% endwith %}

        <!-- 内容块 -->
        {% block content %}{% endblock %}
    </div>
</div>

<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>
    // 初始化侧边栏状态
    function initSidebar() {
        const isHidden = localStorage.getItem('sidebarHidden') === 'true';
        const isMobile = window.innerWidth <= 992;

        if (isMobile) {
            // 移动端默认隐藏侧边栏
            $('.sidebar').removeClass('mobile-active');
            $('#overlay').removeClass('active');
            $('#contentArea').removeClass('expanded');
        } else {
            // 桌面端根据保存的状态设置
            if (isHidden) {
                $('.sidebar').addClass('collapsed');
                $('#contentArea').addClass('expanded');
                $('#toggleSidebarGlobal').html('<i class="fas fa-eye"></i>');
            } else {
                $('.sidebar').removeClass('collapsed');
                $('#contentArea').removeClass('expanded');
                $('#toggleSidebarGlobal').html('<i class="fas fa-eye-slash"></i>');
            }
        }
    }

    // 侧边栏切换（移动端）
    $('#sidebarToggle').on('click', function(e) {
        e.stopPropagation();
        $('.sidebar').toggleClass('mobile-active');
        $('#overlay').toggleClass('active');
    });

    // 全局侧边栏显示/隐藏切换（桌面端）
    $('#toggleSidebarGlobal').on('click', function() {
        const isCollapsed = $('.sidebar').hasClass('collapsed');

        if (isCollapsed) {
            // 显示侧边栏
            $('.sidebar').removeClass('collapsed');
            $('#contentArea').removeClass('expanded');
            $(this).html('<i class="fas fa-eye-slash"></i>');
            localStorage.setItem('sidebarHidden', 'false');
        } else {
            // 隐藏侧边栏
            $('.sidebar').addClass('collapsed');
            $('#contentArea').addClass('expanded');
            $(this).html('<i class="fas fa-eye"></i>');
            localStorage.setItem('sidebarHidden', 'true');
        }
    });

    // 遮罩层点击关闭（移动端）
    $('#overlay').on('click', function() {
        $('.sidebar').removeClass('mobile-active');
        $('#overlay').removeClass('active');
    });

    // 自动关闭提示
    setTimeout(() => {
        $('.alert').alert('close');
    }, 5000);

    // 响应式调整
    function handleResize() {
        const isHidden = localStorage.getItem('sidebarHidden') === 'true';

        if (window.innerWidth > 992) {
            // 桌面端
            $('.sidebar').removeClass('mobile-active');
            $('#overlay').removeClass('active');

            if (isHidden) {
                $('.sidebar').addClass('collapsed');
                $('#contentArea').addClass('expanded');
                $('#toggleSidebarGlobal').html('<i class="fas fa-eye"></i>');
            } else {
                $('.sidebar').removeClass('collapsed');
                $('#contentArea').removeClass('expanded');
                $('#toggleSidebarGlobal').html('<i class="fas fa-eye-slash"></i>');
            }
        } else {
            // 移动端
            $('.sidebar').removeClass('collapsed');
            $('.sidebar').removeClass('mobile-active');
            $('#contentArea').removeClass('expanded');
            $('#overlay').removeClass('active');
        }
    }

    // 初始化
    $(document).ready(function() {
        initSidebar();

        // 窗口调整大小时重新初始化
        $(window).on('resize', handleResize);

        // 点击其他地方关闭侧边栏（移动端）
        $(document).on('click', function(e) {
            if ($(window).width() <= 992 &&
                !$(e.target).closest('.sidebar').length &&
                !$(e.target).is('#sidebarToggle') &&
                $('.sidebar').hasClass('mobile-active')) {
                $('.sidebar').removeClass('mobile-active');
                $('#overlay').removeClass('active');
            }
        });

        // 点击菜单项后关闭侧边栏（移动端）
        $('.menu-item').on('click', function() {
            if (window.innerWidth <= 992) {
                $('.sidebar').removeClass('mobile-active');
                $('#overlay').removeClass('active');
            }
        });
    });
</script>
</body>
</html>